#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>

MODULE_LICENSE("GPL");

static unsigned int major = 0;
static unsigned int minor = 0;
static dev_t devt;

static int __init led_drv_init(void)
{
    int rc = 0;

    if (major)//静态分配，如果有主设备号的话
    {
        devt = MKDEV(major, minor);
        rc = register_chrdev_region(devt, 1, "leds");
        if (rc)
        {
            printk("static register failed!");
            return rc;
        }
    }
    else
    {
        if (alloc_chrdev_region(&devt, 100, 1, "leds"))
        {
            pr_err("QAT: unable to allocate chrdev region\n");
		    return -EFAULT;
        }

        printk("major = %d, minor = %d\n", MAJOR(devt), MINOR(devt));
    }
    return 0;
}

static void __exit led_drv_exit(void)
{
    unregister_chrdev_region(devt, 1);
}

module_init(led_drv_init);
module_exit(led_drv_exit);